package com.tmt.paymentcenter.web.domain;

import com.tmt.jpafieldvalueconvert.JpaFieldValueConvertListener;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import tmt.usercenter.web.domain.BaseDomain;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * 用户的账户
 */
@Getter
@Setter
@Entity
@EntityListeners({AuditingEntityListener.class})
public class Account extends BaseDomain implements Serializable {

    /**
     * 账户余额
     */
    @Column(nullable = false)
    private BigDecimal Balance = BigDecimal.ZERO;

    /**
     * 账户类型
     */
    @ManyToOne(cascade = {CascadeType.REFRESH}, optional = false)
    @JoinColumn(name="accountType_id", nullable = false)
    private AccountType accountType;

    /**
     * 账户所属人
     */
    @ManyToOne(cascade = {CascadeType.REFRESH}, optional = false)
    @JoinColumn(name="tradeUser_id", nullable = false)
    private TradeUser tradeUser;

    /**
     * 作为收入账户关联的交易记录。
     */
    @OneToMany(mappedBy = "inAccount", cascade = {CascadeType.REFRESH})
    private List<TradeDetailHistory> inTradeDetailHistories;

    /**
     * 作为支出账户关联的交易记录。
     */
    @OneToMany(mappedBy = "outAccount", cascade = {CascadeType.REFRESH})
    private List<TradeDetailHistory> outTradeDetailHistories;

}
